home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-17 | 3.7 KB | 152 lines | [TEXT/MPS ] |
- // UFailure.h
- // Copyright © 1984-1992 by Apple Computer Inc. All rights reserved.
-
- #ifndef __UFAILURE__
- #define __UFAILURE__
-
- #ifdef NEVER
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
- #else
- #ifndef __PASCALSTRING__
- #include "PascalString.h"
- #endif
- #endif
-
- //----------------------------------------------------------------------------------------
- // This macro can be called on any variable to keep it out of a register. It is
- // used specifically in exception handling. Cludge to be used till volatile or
- // C++ exception handling is implemented.
- //----------------------------------------------------------------------------------------
-
- #define VOLATILE(a) ((void) &a)
-
-
- //----------------------------------------------------------------------------------------
- // Max and min error number constants
- //----------------------------------------------------------------------------------------
-
- const short minErr = -32768;
- const short maxErr = 32767;
-
-
- //----------------------------------------------------------------------------------------
- // FailInfo
- //----------------------------------------------------------------------------------------
-
- class FailInfo
- {
- public:
- long regs[12];
- short flags;
- short error;
- long message;
- long failA6;
- long failPC;
- FailInfo* nextInfo;
- #if qDebug
- long whoPC;
- short installed;
- #endif
-
- public:
- FailInfo();
-
- #if qDebug
- ~FailInfo();
- #endif
-
- inline Boolean Try();
-
- inline void ReSignal();
-
- inline void Success();
- };
-
- typedef struct FailInfo *FailInfoPtr;
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations
- //----------------------------------------------------------------------------------------
-
- extern FailInfoPtr gTopHandler;
-
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
- pascal void Assertion(const Boolean condition, const CStr255& description);
-
- pascal long BuildMessage(short lowWord, short highWord)
- { return (long)highWord << 16 & lowWord; }
-
- typedef pascal void(* CatchFailuresType)(short e, long m, void* staticLink);
-
- pascal void CatchFailures(FailInfo& fi, CatchFailuresType Handler, void* staticLink);
-
- typedef pascal void(* DoToHandlerType)(FailInfoPtr fiPtr, void* staticLink);
-
- pascal void EachFailureHandlerDo(DoToHandlerType DoToHandler, void* staticLink);
-
- pascal void Failure(OSErr error, long message);
-
- pascal void FailMemError();
-
- pascal void FailResError();
-
- pascal void FailNewMessage(OSErr error, long oldMessage, long newMessage);
-
- pascal void FailNIL(void* p);
-
- pascal void FailNILResource(Handle r);
-
- pascal void FailOSErr(OSErr error);
-
- pascal Boolean HandlerExists(FailInfoPtr testFailInfoPtr);
-
- pascal void Success(FailInfo& fi);
-
- pascal void ProgramBreak(const CStr255& grievance);
-
- pascal void ProgramReport(const CStr255& grievance, const Boolean breakInDebugger);
-
- extern "C" {
- extern Boolean Try(FailInfo& fi);
- }
-
- //----------------------------------------------------------------------------------------
- // FailInfo inline method definitions
- //----------------------------------------------------------------------------------------
-
- inline FailInfo::FailInfo()
- {
- #if qDebug
- installed = FALSE;
- #endif
- }
-
- #if qDebug
- inline FailInfo::~FailInfo()
- {
- if (installed)
- ProgramBreak("You forgot to call success for your failure handler");
- }
- #endif
-
- inline Boolean FailInfo::Try() { return ::Try(*this); }
-
- inline void FailInfo::ReSignal() { ::Failure(error, message); }
-
- #if qDebug
- inline void FailInfo::Success() { ::Success(*this); }
- #else
- inline void FailInfo::Success() { gTopHandler = nextInfo; }
- #endif
-
- #endif
-
-
-